<!DOCTYPE html>
<html>
<head>
    <title>我的消息</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/message.css"/>
    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            var userId = user.id;
            $.get('/allMessages/' + userId, function (data) {
                console.log(data);
                var privateMessageCount = data.privateMessageCount;
                var systemMessageCount = data.systemMessageCount;
                var likeCount = data.likeCount;
                var queryCommentCount = data.queryCommentCount;
                $(".list-group").renderValues(data);
                if (privateMessageCount == 0) {
                    $("#privateLetter").remove();
                }
                if (systemMessageCount == 0) {
                    $("#systemLetter").remove();
                }
                if (likeCount == 0) {
                    $("#like").remove();
                }
                if (queryCommentCount == 0) {
                    $("#myComment").remove();
                }
            });
            $("#system").click(function () {
                $.ajax({
                    url: "/systemMessages/" + userId,
                    type: "PUT",
                    success: function (data) {
                        console.log(data);
                        if (data.success) {
                            window.location.href = "/mine/myMessage.html";
                        }
                    }
                });
            });
            $("#likeMessage").click(function () {
                $.ajax({
                    url: "/likeMessages/" + userId,
                    type: "PUT",
                    success: function (data) {
                        console.log(data);
                        if (data.success) {
                            window.location.href = "/mine/like.html";
                        }
                    }
                });
            });
        });
    </script>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="/mine/profiles.html">
                <span><i class="fa fa-chevron-left"></i></span>
            </a>
        </div>
        <div class="col">
            <span>我的消息</span>
        </div>
        <div class="col"></div>
    </div>
</div>

<ul class="list-group">
    <a href="javascript:" id="likeMessage">
        <li class="list-group-item d-flex justify-content-between align-items-center">
            <div class="item">
                <span><i class="fa fa-thumbs-o-up"></i></span>
                <span>赞</span>
                <span class="badge badge-danger badge-pill" render-html="likeCount" id="like"></span>
            </div>
            <i class="fa fa-chevron-right"></i>
        </li>
    </a>
    <a href="/mine/MyComment.html">
        <li class="list-group-item d-flex justify-content-between align-items-center">
            <div class="item">
                <span><i class="fa fa-commenting-o"></i></span>
                <span>评论</span>
                <span class="badge badge-danger badge-pill" render-html="queryCommentCount" id="myComment"></span>
            </div>
            <i class="fa fa-chevron-right"></i>
        </li>
    </a>
    <a href="/mine/privateLetter.html">
        <li class="list-group-item d-flex justify-content-between align-items-center">
            <div class="item">
                <span><i class="fa fa-envelope-o"></i></span>
                <span>私信</span>
                <span class="badge badge-danger badge-pill" render-html="privateMessageCount" id="privateLetter"></span>
            </div>
            <i class="fa fa-chevron-right"></i>
        </li>
    </a>
    <a href="javascript:" id="system">
        <li class="list-group-item d-flex justify-content-between align-items-center">
            <div class="item">
                <span><i class="fa fa-bell"></i></span>
                <span>系统通知</span>
                <span class="badge badge-danger badge-pill" render-html="systemMessageCount" id="systemLetter"></span>
            </div>
            <i class="fa fa-chevron-right"></i>
        </li>
    </a>
</ul>
</body>
</html>